<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <link rel="apple-touch-icon" sizes="76x76" href="{_INDEX_STATIC_}/moban/assets/img/apple-icon.png">
    <link rel="icon" type="image/png" href="{_INDEX_STATIC_}/moban/assets/img/favicon.png">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>首页 | {$system_name}</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
        name='viewport' />
    <link href="{_INDEX_STATIC_}/moban/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="{_INDEX_STATIC_}/moban/assets/css/now-ui-kit.css?v=1.1.0" rel="stylesheet" />
</head>

<body class="index-page sidebar-collapse">

    <!-- 引入导航栏 -->
    {include file='public/header'}

    <div class="container" style="min-height: 410px;">
        <div class="row" style="margin-top: 80px;">
            <!-- 昵称 年龄 Start -->
            <div class="col-md-2"></div>
            <div class="col-md-8">
                <div class="input-group">
                    <span class="input-group-addon">
                        旧密码
                    </span>
                    <input id="old_password" type="password" class="form-control" placeholder="请输入旧密码">
                </div>
            </div>
            <div class="col-md-2"></div>
            <div class="col-md-2"></div>
            <div class="col-md-8">
                <div class="input-group">
                    <span class="input-group-addon">
                        新密码
                    </span>
                    <input id="new_password" type="password" class="form-control" placeholder="请输入新密码">
                </div>
            </div>
            <div class="col-md-2"></div>
            <div class="col-md-2"></div>
            <div class="col-md-8">
                <div class="input-group">
                    <span class="input-group-addon">
                        确认密码
                    </span>
                    <input id="confirm_password" type="password" class="form-control" placeholder="请输入确认密码">
                </div>
            </div>
            <div class="col-md-2"></div>
            <!-- 昵称 年龄 End -->

            <div class="col-md-6" style="text-align: center;">
                <button id="save" class="btn btn-success btn-round btn-lg">点击修改</button>
            </div>
            <div class="col-md-6" style="text-align: center;">
                <button id="back" class="btn btn-info btn-round btn-lg">点击返回</button>
            </div>

        </div>
    </div>
    <!-- 引入页脚 -->
    {include file='public/footer'}

    <script>

        // 点击保存
        $('#save').on('click', function () {
            // 收集数据
            var uid = "{$user_id}";
            var old_password = $('#old_password').val().trim();
            var new_password = $('#new_password').val().trim();
            var confirm_password = $('#confirm_password').val().trim();

            if (old_password == '') {
                return layer.msg('旧密码不能为空', { icon: 2, time: 900 });
            }
            if (new_password == '') {
                return layer.msg('新密码不能为空', { icon: 2, time: 900 });
            }
            if (confirm_password == '') {
                return layer.msg('确认密码不能为空', { icon: 2, time: 900 });
            }
            if (new_password.length < 6) {
                return layer.msg('密码成都不能少于6位', { icon: 2, time: 900 });
            }
            if (new_password != confirm_password) {
                return layer.msg('两次密码不一致', { icon: 2, time: 900 });
            }

            var data = {
                'uid': uid,
                'old_password': old_password,
                'new_password': new_password,
                'confirm_password': confirm_password,
            };

            $.ajax({
                url: "{:url('User/user_password')}",
                data: data,
                type: "POST",
                dataType: "JSON",
                success: function (res) {
                    // 返回结果处理
                    if (res.code == 0) {
                        return layer.msg(res.msg, { icon: 1, time: 900 },function(){
                            $('#old_password').val('');
                            $('#new_password').val('');
                            $('#confirm_password').val('');
                        });
                    } else {
                        return layer.msg(res.msg, { icon: 2, time: 900 });
                    }
                }
            });
        });

        // 点击返回
        $('#back').on('click', function () {
            window.location.href = document.referrer;
        });

    </script>


</body>

</html>